/*
 * Copyright 2002-2006 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package pikes.xml;

import pikes.core.Printer;

/**
 * Printing format configuration by which one can create nicely formatted XML content. The following properties can be
 * configured:
 * <ul>
 * <li><code>indenting</code>. If true, indentation is turned on, otherwise it is off. Default is true.</li>
 * <li><code>numberOfSpaces</code>. Sets the number of space characters should be used for tabbing. Default is 8.</li>
 * <li><code>useTab</code>. If the '\t' should be used for tabbing. Default is false.</li>
 * <li><code>expandEmptyTag</code>. If true, empty tags should be expanded when printing. Default is true.</li>
 * </ul>
 * @author Peter Bona
 * @see XMLFormatter
 */
public class PrettyPrintingConfiguration implements XMLFormattingConfiguration {

	/**
	 * Default number of spaces is 8.
	 */
	public static final int DEFAULT_NUMBER_OF_SPACES = 8;

	private boolean isIndenting = true;

	private boolean useTab = false;

	private int numberOfSpaces = DEFAULT_NUMBER_OF_SPACES;

	private boolean expandEmptyTag = true;

	private boolean newLine = true;

	/**
	 * Creates {@link XMLFormatter}
	 */
	public final XMLVisitor createXMLPrinter(Appendable appendable) {
		if (useTab) {
			return new XMLFormatter(new Printer(appendable, expandEmptyTag), newLine, isIndenting, useTab);
		}
		else {
			return new XMLFormatter(new Printer(appendable, false, numberOfSpaces), expandEmptyTag, newLine,
					isIndenting);
		}

	}

	/**
	 * @return true if indentation is on, false otherwise.
	 */
	public final boolean isIndenting() {
		return isIndenting;
	}

	/**
	 * @param isIndenting If true, indenting is on. If false, indenting is off.
	 */
	public final void setIndenting(boolean isIndenting) {
		this.isIndenting = isIndenting;
	}

	/**
	 * @return true, if the use of '\t' as tabulator is on, false otherwise.
	 */
	public final boolean isUseTab() {
		return useTab;
	}

	/**
	 * @param useTab If true, '\t'is used for indenting. If false, ' ' is used.
	 */
	public final void setUseTab(boolean useTab) {
		this.useTab = useTab;
	}

	/**
	 * @return the number of space characters to use as tabulator.
	 */
	public final int getNumberOfSpaces() {
		return numberOfSpaces;
	}

	/**
	 * @param numberOfSpaces The number of ' ' characters to use for indenting.
	 */
	public final void setNumberOfSpaces(int numberOfSpaces) {
		this.numberOfSpaces = numberOfSpaces;
	}

	public final boolean isExpandEmptyTag() {
		return expandEmptyTag;
	}

	public final void setExpandEmptyTag(boolean expandEmptyTag) {
		this.expandEmptyTag = expandEmptyTag;
	}

	public final boolean isNewLine() {
		return newLine;
	}

	public final void setNewLine(boolean newLine) {
		this.newLine = newLine;
	}

}
